package com.auxgroup.hr.front.site.co.modPerson;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.auxgroup.hr.front.site.vo.modperson.ModBankAcctQueFrom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCModBankacct;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.modperson.ModBankacctService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.vo.modperson.ModBankAcctQueFrom;

/**
 * 银行卡流程信息CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/modBankacct")
public class ModBankacctCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(ModBankacctCO.class);

	@Autowired
	public ModBankacctService modBankacctService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 保存银行卡流程信息
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(@Valid ModBankAcctQueFrom modBankacctForm, BindingResult binding) {
		logger.info("saveModBankacct param= {}", modBankacctForm);
		// 表单校验
        super.assertValidation(binding);
        PsCModBankacct modBankacct = modBankacctService.getModBankacct(modBankacctForm.getcTransactionNbr());
        if(modBankacct!=null){
        	objectMapper.map(modBankacctForm, modBankacct,"notCopyNull_modBank");
        }else{
        	modBankacct = objectMapper.map(modBankacctForm, PsCModBankacct.class);
        }
        modBankacct = modBankacctService.save(modBankacct);
		if(modBankacct.getEmplid()!=null){
			return buildRespone(true);
		}
		return buildRespone(false);
		
	}
	
	/**
	 * 获取银行卡流程信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String cTransactionNbr) {
		logger.info("getModBankacct param= {}", cTransactionNbr);
		PsCModBankacct modBankacct = modBankacctService.getModBankacct(cTransactionNbr);
		return buildRespone(modBankacct);
	}
	
}
